﻿// See https://aka.ms/new-console-template for more information
using System;
abstract class Shape
{
 
    public abstract Double Area();
}
 class Rectangle:Shape
{   
    public Rectangle()
    {
        Random random = new Random();
        Width =random.NextDouble() * 10;
        Height =random.NextDouble() * 10;
    }
    private double Width
    { get; set; }
    private double Height
    { get; set; }

    public override double Area()
    {
       return Width * Height;
    }
}

class Trangle:Shape
{
    public Trangle()
    {
        Random rand = new Random();
        //do
        //{
            a = rand.NextDouble() * 10;
            b = rand.NextDouble() * 10;
            c = rand.NextDouble() * 10;
        //}while(a+b>c&&a+c>b&&b+c>a);
        

    }
    private double a
    { get; set; }
    private double b
    { get; set; }
    private double c
    { get; set; }

    public override double Area()
    {
        if (a + b > c && a + c > b && b + c > a)
        {

            double p = (a + b + c) / 2;
            return Math.Sqrt(p * (p - b) * (p - c) * (p - a));
        }
        else
            return 0;
       
    }
}

class Circle:Shape
{
    public Circle()
    {
        Random rand = new Random();
        Radius =rand.NextDouble()*10;
    }
    private double Radius
    { get; set; }
    public override double Area()
    {
        return Radius * Radius*Math.PI;
    }
}
class Factory
{
    
    public static Shape GetShape(string s)
    {
        Shape shape = null;
        if(s.Equals("Rectangle"))
        {
            shape=new Rectangle();
        }
        if(s.Equals("Trangle"))
        {
            shape= new Trangle();
        }
        if(s.Equals("Circle"))
        {
            shape = new Circle();
        }
        return shape;
    }
}

public class Program
{
    public static void Main(string[] args)
    {
        Random random = new Random();
        double sum= 0.0;int n;
        string[] s= {"Rectangle","Circle","Trangle"};
        for(int i=0;i<10;i++)
        {
            n=random.Next(3);
            Shape s1 = Factory.GetShape(s[n]);
            sum+=s1.Area();
            Console.WriteLine(s[n]+" : "+s1.Area());
        }
        Console.WriteLine("随机十个形状的面积为："+sum);
    }
}